// pages/order/newOrder/newOrder.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    params: {},
    showUrl: '',
    picList: []
  },
  //图片点击事件
  imgYu: function (e) {
    console.log(e)
    var that=this;
    var src = e.currentTarget.dataset.item;//获取data-src
    var imgList = that.data.picList;//获取data-list
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  detail() {
    let id = this.data.id;
    let that = this;
    app.req({
      url: "/order/busOrder/queryById",
      data: {
        id
      },
      success(res) {
        if (200 == res.code) {
          that.toggle("params", res.result);
          that.picList();
        }
      }
    })
  },
  picList() {
    let id = this.data.id;
    let that = this;
    app.req({
      url: "/order/busOrder/queryBusOrderPicsByMainId",
      data: {
        id
      },
      success(res) {
        if (200 == res.code) {
          let list = res.result;
          let picList = [];
          for (let i of list) {
            picList.push(that.data.showUrl+i.picUrls);
          }
          that.toggle("picList", picList);
        }
      }
    })
  },
  login(f) {
    app.getUserInfo({
      success(res) {
        f && f(res);
      },
      error() {
        console.log("err")
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.toggle("showUrl", app.globalData.showUrl);
    this.toggle("id", options.id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    that.login(function (res) {
      that.detail();
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})